package alipay

import (
	"github.com/smartwalle/alipay/v3"
	"strconv"
)

type Refund struct {
	OutTradeNo  string `json:"outTradeNo"`
	OutRefundNo string `json:"outRefundNo"`
	Total       int64  `json:"total"`
	Refund      int64  `json:"refund"`
}

func (refund *Refund) Done() (string, error) {
	var p = alipay.TradeRefund{}
	p.OutTradeNo = refund.OutRefundNo
	num := float64(refund.Total) / 100.0
	str := strconv.FormatFloat(num, 'f', 2, 64)
	p.RefundAmount = str
	p.OutRequestNo = refund.OutRefundNo
	res, err := MyClient.AlipayClient.TradeRefund(p)
	if err != nil {
		return "", err
	}
	return res.Msg, nil
}
